package com.ciaojian.client.controller;

import com.ciaojian.client.service.OrderServiceImpl;
import com.ciaojian.client.service.UserTimesCardServiceImpl;
import com.ciaojian.core.mapper.UserTimesCardMapper;
import com.ciaojian.core.model.Order;
import com.ciaojian.core.model.UserTimesCard;
import com.ciaojian.core.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author oxiny
 */
@Api(tags = "用户模块: 用户次卡")
@RestController
@RequestMapping("/user-times-card")
public class UserTimesCardController {
    @Resource
    private UserTimesCardServiceImpl<UserTimesCardMapper, UserTimesCard> userTimesCardService;
    @Resource
    private OrderServiceImpl orderService;

    @ApiModelProperty("支付可用次卡")
    @GetMapping("/usable")
    public Result getUserTimesCardUsable(String orderNo) {
        Order order = orderService.getByOrderNo(orderNo);
        return Result.ok(userTimesCardService.listUserTimesCardUsable(order.getUserId(), order.getStoreId(), order.getType()));
    }

    @ApiModelProperty("有效次卡")
    @GetMapping("/{userId}")
    public Result getUserTimesCard(@PathVariable Integer userId) {
        return Result.ok(userTimesCardService.listUserTimesCard(userId));
    }
}
